#!/usr/bin/python
# -*- coding: utf-8 -*-




def count1(x):
    count =0
    l = bin(x)
    for i in range(len(l)):
        if(l[i]=='1'):
            count += 1
    return count
def countn(x):
    count=0
    l=str(x)
    for i in range(len(l)):
        count+=int(l[i])
    return count



if __name__=="__main__":
    n = raw_input()
    num = int(n)
    cnt = 0
    for i in range(1, num+1):
        if (count1(i)==countn(i)):
            cnt+=1
    print(cnt)